/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xuidemo.slice;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.slice.refreshlayout.SampleListAbilitySlice;

/**
 * xinglu
 *
 * @since 2021-04-20
 */
public class RefreshLayoutAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Image mImageBack;
    private DirectionalLayout mDlOne;
    private DirectionalLayout mDlTwo;
    private DirectionalLayout mDlThree;
    private DirectionalLayout mDlFour;
    private DirectionalLayout mDlFive;
    private DirectionalLayout mDlSix;
    private DirectionalLayout mDlSeven;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_refreshlayout);
        initComponent();
        initClickedListener();

    }

    /**
     * 初始化view
     */
    public void initComponent() {
        mImageBack = (Image) findComponentById(ResourceTable.Id_image_back);
        mDlOne = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_one);
        mDlTwo = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_two);
        mDlThree = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_three);
        mDlFour = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_four);
        mDlFive = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_five);
        mDlSix = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_six);
        mDlSeven = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_seven);
    }

    private void initClickedListener() {
        mImageBack.setClickedListener(this);
        mDlOne.setClickedListener(this);
        mDlTwo.setClickedListener(this);
        mDlThree.setClickedListener(this);
        mDlFour.setClickedListener(this);
        mDlFive.setClickedListener(this);
        mDlSix.setClickedListener(this);
        mDlSeven.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_dl_one:
                break;
            case ResourceTable.Id_dl_two:
                break;
            case ResourceTable.Id_dl_three:
                break;
            case ResourceTable.Id_dl_four:
                break;
            case ResourceTable.Id_dl_five:
                break;
            case ResourceTable.Id_dl_six:
                present(new RefreshStickyListAbilitySlice(), new Intent());
                break;
            case ResourceTable.Id_dl_seven:
                present(new SampleListAbilitySlice(), new Intent());
                break;
            default:
                break;
        }
    }
}
